<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
</head>

<body>
    <script>
        let myWorker = new Worker('./worker.js')

        myWorker.onerror = function (e) {
            console.log('您的Worker出现错误！一般是js文件引入错误',)
        }

        myWorker.onmessageerror = function (e) {
            console.log('接受的信息不能被序列化', e)
        }

        // 监听信息来源是Worker时触发。
        myWorker.onmessage = function (e) {
            console.log('接受来自worker的数据：', e)
            console.log('接受来自worker的数据：', e.data)
        }

        // 给Worker传值
        myWorker.postMessage('传值到worker中。。。。。。')

        // 关闭Worker
        // myWorker.terminate()

    </script>

</body>

</html>